<template>
  <div class="home">
    <slide-show v-if="viewWidth" :SlideshowData="SlideshowData"></slide-show>
    <slide-vue v-else :SlideshowData="SlideshowData"></slide-vue>
    <div class="home-centent">
      <div class="xihuan-box">
        <svg class="icon icon-xihuan" aria-hidden="true">
          <use xlink:href="#icon-cainixihuan1"></use>
        </svg>
        <span class="icon-xihuans">猜你喜欢</span>
        <switch-list :result="switchList"></switch-list>
      </div>
      <div class="video-box">
        <video-list :VideoData="videoData"></video-list>
      </div>
    </div>
    
  </div>
</template>

<script>
import { mapActions } from 'vuex';
import SlideShow from '../home/slideshow/slideshow.vue'
import SwitchList from '../home/switchover/list.vue'
import VideoList from '../home/videoList/list.vue'
import slideVue from '../home/slidemobe/slide.vue'
export default {
  name: 'Home',

  data() {
    return {
      SlideshowData: [], // 轮播图数据集
      videoData: [], // 视频数据集
      switchList: null, // tab切换数据集
      width: window.innerWidth // 当前游览器可视宽度
    }
  },

  created(){
    window.addEventListener('resize',this.getViewWidth)
  },

  mounted(){
    this.init()
  },

  computed:{
    viewWidth(){
      return this.width >= 1000
    }
  },

  methods: {
    // 初始化
    init(){
      this.$api.getHomeInfo().then(res => {
        if(res instanceof Object){
          this.videoData = res.video
          this.switchList = {
            article: res.article,
            topics: res.topics,
            host: res.host,
            message: res.message
          }
          this.SlideshowData = res.slides
        }else{
          this.showHint({title:'加载失败',isFlag:false})
          this.$router.push('/404')
        }
      })
    },
    // 获取游览器可视宽度
    getViewWidth(){
      this.width = window.innerWidth
    },
    ...mapActions(['showHint'])
  },

  components: {
    SlideShow,
    SwitchList,
    VideoList,
    slideVue
  }
};
</script>

<style scoped>
.home-centent{
  width: 100%;
  border-top: 1px solid gray;
  display: flex;
  justify-content: space-between;
}
.xihuan-box{
  border-right: 1px solid gray;
  padding-top: 20px;
}
.icon-xihuan{
  font-size: 40px;
  margin: 0 10px;
}
.video-box{
  flex: 1;
}
.icon-xihuans{
  font-size: 30px;
  vertical-align: top;
  color: rgb(252, 198, 19);
  font-weight: 600;
}

@media screen and (max-width: 800px) {
  .switch-list{
    width: 100%;
  }
  .home-centent{
    flex-direction: column;
  }
}
</style>